﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;
using System.Text;

namespace GPCSC.Web.sjsbyes
{
    public partial class qsls : PageBase
    {
        public StringBuilder xjc = new StringBuilder();//统计历史
        protected void Page_Load(object sender, EventArgs e)
        {
            load();
        }
        protected void load()
        {
            DataSet ds = new DataSet();
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable htable = new Hashtable();

            ds = new SqlReadXml().ReaderDataSet("sel_tjlss_all", htable);
            if (ds.Tables.Count > 0)
            {

                if (ds.Tables[0].Rows.Count > 0)
                {
                    xjc.Append("<table>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {

                        int mods = i % 3;
                        switch (mods)
                        {

                            case 0:
                                xjc.Append("<tr>");
                                xjc.Append("<td ><img src=\"../sjs/image/lb.jpg\"  /><br /><input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                break;
                            case 1:
                                xjc.Append("<td ><img src=\"../sjs/image/lb.jpg\" /><br /><input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                break;
                            case 2:
                                xjc.Append("<td ><img src=\"image/lb.jpg\"  /><br /> <input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                xjc.Append("</tr>");
                                break;
                        }
                    }
                    int len = ds.Tables[0].Rows.Count;
                    if (len % 3 != 0)
                    {
                        xjc.Append("</tr>");
                    }
                    xjc.Append("</table>");
                }
            }

        }



        protected void Button1_Click(object sender, EventArgs e)
        {
            string ids = this.ids.Value;
            string filename = geifile(ids);
            Response.Clear();
            System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
            //stringWriter.Write("<div>ceshi</div>");
            Response.BufferOutput = true;
            //设定输出的字符集
            Response.Charset = "GB2312";
            //假定导出的文件名为FileName.doc
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            /**/
            ////设置导出文件的格式
            Response.ContentType = "application/ms-word";

            System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
            panl.RenderControl(textWriter);


            Response.Write(stringWriter.ToString());
            Response.End();
        }
        protected string geifile(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                Hashtable htable = new Hashtable();
                htable.Add("@FileID", id);
                DataSet ds = new SqlReadXml().ReaderDataSet("tifilebyiod", htable);
                panl.InnerHtml = ds.Tables[0].Rows[0]["fileUrl"].ToString();

                return ds.Tables[0].Rows[0]["filename"].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
}